<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE DerivingStrategies #-}</span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# LANGUAGE GeneralizedNewtypeDeriving #-}</span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# LANGUAGE MagicHash #-}</span><span>
</span><span id="line-5"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude #-}</span><span>
</span><span id="line-6"></span><span class="hs-pragma">{-# LANGUAGE StandaloneDeriving #-}</span><span>
</span><span id="line-7"></span><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-8"></span><span>
</span><span id="line-9"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Module      :  Foreign.Ptr</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Copyright   :  (c) The FFI task force 2001</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Maintainer  :  ffi@haskell.org</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- Stability   :  provisional</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-18"></span><span class="hs-comment">--</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- This module provides typed pointers to foreign data.  It is part</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- of the Foreign Function Interface (FFI) and will normally be</span><span>
</span><span id="line-21"></span><span class="hs-comment">-- imported via the &quot;Foreign&quot; module.</span><span>
</span><span id="line-22"></span><span class="hs-comment">--</span><span>
</span><span id="line-23"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-24"></span><span>
</span><span id="line-25"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Foreign.Ptr</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-26"></span><span>
</span><span id="line-27"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Data pointers</span></span><span>
</span><span id="line-28"></span><span>
</span><span id="line-29"></span><span>    </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier">Ptr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-30"></span><span>    </span><span class="annot"><a href="GHC.Ptr.html#nullPtr"><span class="hs-identifier">nullPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-31"></span><span>    </span><span class="annot"><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier">castPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-32"></span><span>    </span><span class="annot"><a href="GHC.Ptr.html#plusPtr"><span class="hs-identifier">plusPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-33"></span><span>    </span><span class="annot"><a href="GHC.Ptr.html#alignPtr"><span class="hs-identifier">alignPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-34"></span><span>    </span><span class="annot"><a href="GHC.Ptr.html#minusPtr"><span class="hs-identifier">minusPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-35"></span><span>
</span><span id="line-36"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Function pointers</span></span><span>
</span><span id="line-37"></span><span>
</span><span id="line-38"></span><span>    </span><span class="annot"><a href="GHC.Ptr.html#FunPtr"><span class="hs-identifier">FunPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-39"></span><span>    </span><span class="annot"><a href="GHC.Ptr.html#nullFunPtr"><span class="hs-identifier">nullFunPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-40"></span><span>    </span><span class="annot"><a href="GHC.Ptr.html#castFunPtr"><span class="hs-identifier">castFunPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-41"></span><span>    </span><span class="annot"><a href="GHC.Ptr.html#castFunPtrToPtr"><span class="hs-identifier">castFunPtrToPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-42"></span><span>    </span><span class="annot"><a href="GHC.Ptr.html#castPtrToFunPtr"><span class="hs-identifier">castPtrToFunPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-43"></span><span>
</span><span id="line-44"></span><span>    </span><span class="annot"><a href="Foreign.Ptr.html#freeHaskellFunPtr"><span class="hs-identifier">freeHaskellFunPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-45"></span><span>    </span><span class="hs-comment">-- Free the function pointer created by foreign export dynamic.</span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Integral types with lossless conversion to and from pointers</span></span><span>
</span><span id="line-48"></span><span>    </span><span class="annot"><a href="Foreign.Ptr.html#IntPtr"><span class="hs-identifier">IntPtr</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-49"></span><span>    </span><span class="annot"><a href="Foreign.Ptr.html#ptrToIntPtr"><span class="hs-identifier">ptrToIntPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-50"></span><span>    </span><span class="annot"><a href="Foreign.Ptr.html#intPtrToPtr"><span class="hs-identifier">intPtrToPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-51"></span><span>    </span><span class="annot"><a href="Foreign.Ptr.html#WordPtr"><span class="hs-identifier">WordPtr</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-52"></span><span>    </span><span class="annot"><a href="Foreign.Ptr.html#ptrToWordPtr"><span class="hs-identifier">ptrToWordPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-53"></span><span>    </span><span class="annot"><a href="Foreign.Ptr.html#wordPtrToPtr"><span class="hs-identifier">wordPtrToPtr</span></a></span><span>
</span><span id="line-54"></span><span>
</span><span id="line-55"></span><span>    </span><span class="hs-comment">-- See Note [Exporting constructors of marshallable foreign types]</span><span>
</span><span id="line-56"></span><span>    </span><span class="hs-comment">-- for why the constructors for IntPtr and WordPtr are exported.</span><span>
</span><span id="line-57"></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Ptr.html"><span class="hs-identifier">GHC.Ptr</span></a></span><span>
</span><span id="line-60"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span>
</span><span id="line-62"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Read.html"><span class="hs-identifier">GHC.Read</span></a></span><span>
</span><span id="line-63"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span>
</span><span id="line-64"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Show.html"><span class="hs-identifier">GHC.Show</span></a></span><span>
</span><span id="line-65"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Enum.html"><span class="hs-identifier">GHC.Enum</span></a></span><span>
</span><span id="line-66"></span><span>
</span><span id="line-67"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Bits.html"><span class="hs-identifier">Data.Bits</span></a></span><span>
</span><span id="line-68"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Storable.html"><span class="hs-identifier">Foreign.Storable</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier">Storable</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-69"></span><span>
</span><span id="line-70"></span><span class="hs-comment">-- | Release the storage associated with the given 'FunPtr', which</span><span>
</span><span id="line-71"></span><span class="hs-comment">-- must have been obtained from a wrapper stub.  This should be called</span><span>
</span><span id="line-72"></span><span class="hs-comment">-- whenever the return value from a foreign import wrapper function is</span><span>
</span><span id="line-73"></span><span class="hs-comment">-- no longer required; otherwise, the storage it uses will leak.</span><span>
</span><span id="line-74"></span><span id="local-6989586621679535736"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;freeHaskellFunctionPtr&quot;</span></span><span>
</span><span id="line-75"></span><span>    </span><span id="freeHaskellFunPtr"><span class="annot"><a href="Foreign.Ptr.html#freeHaskellFunPtr"><span class="hs-identifier hs-var">freeHaskellFunPtr</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#FunPtr"><span class="hs-identifier hs-type">FunPtr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679535736"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span class="hs-cpp">

#include &quot;HsBaseConfig.h&quot;
</span><span class="hs-cpp">#include &quot;CTypes.h&quot;
</span><span>
</span><span id="line-80"></span><span class="hs-comment">-- | An unsigned integral type that can be losslessly converted to and from</span><span>
</span><span id="line-81"></span><span class="hs-comment">-- @Ptr@. This type is also compatible with the C99 type @uintptr_t@, and</span><span>
</span><span id="line-82"></span><span class="hs-comment">-- can be marshalled to and from that type safely.</span><span>
</span><span id="line-83"></span><span id="WordPtr"></span><span class="hs-identifier">INTEGRAL_TYPE</span><span class="hs-special">(</span><span class="hs-identifier">WordPtr</span><span class="hs-special">,</span><span class="hs-identifier">Word</span><span class="hs-special">)</span><span>
</span><span id="line-84"></span><span>        </span><span class="hs-comment">-- Word and Int are guaranteed pointer-sized in GHC</span><span>
</span><span id="line-85"></span><span>
</span><span id="line-86"></span><span class="hs-comment">-- | A signed integral type that can be losslessly converted to and from</span><span>
</span><span id="line-87"></span><span class="hs-comment">-- @Ptr@.  This type is also compatible with the C99 type @intptr_t@, and</span><span>
</span><span id="line-88"></span><span class="hs-comment">-- can be marshalled to and from that type safely.</span><span>
</span><span id="line-89"></span><span id="IntPtr"></span><span class="hs-identifier">INTEGRAL_TYPE</span><span class="hs-special">(</span><span class="hs-identifier">IntPtr</span><span class="hs-special">,</span><span class="hs-identifier">Int</span><span class="hs-special">)</span><span>
</span><span id="line-90"></span><span>        </span><span class="hs-comment">-- Word and Int are guaranteed pointer-sized in GHC</span><span>
</span><span id="line-91"></span><span>
</span><span id="line-92"></span><span class="hs-comment">-- | casts a @Ptr@ to a @WordPtr@</span><span>
</span><span id="line-93"></span><span id="local-6989586621679535759"><span class="annot"><a href="Foreign.Ptr.html#ptrToWordPtr"><span class="hs-identifier hs-type">ptrToWordPtr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679535759"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.Ptr.html#WordPtr"><span class="hs-identifier hs-type">WordPtr</span></a></span></span><span>
</span><span id="line-94"></span><span id="ptrToWordPtr"><span class="annot"><span class="annottext">ptrToWordPtr :: forall a. Ptr a -&gt; WordPtr
</span><a href="Foreign.Ptr.html#ptrToWordPtr"><span class="hs-identifier hs-var hs-var">ptrToWordPtr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span id="local-6989586621679535052"><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679535052"><span class="hs-identifier hs-var">a#</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word -&gt; WordPtr
</span><a href="Foreign.Ptr.html#WordPtr"><span class="hs-identifier hs-var">WordPtr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word# -&gt; Word
</span><a href="../../ghc-prim/src/GHC.Types.html#W%23"><span class="hs-identifier hs-var">W#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int# -&gt; Word#
</span><a href="../../ghc-prim/src/GHC.Prim.html#int2Word%23"><span class="hs-identifier hs-var">int2Word#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Addr# -&gt; Int#
</span><a href="../../ghc-prim/src/GHC.Prim.html#addr2Int%23"><span class="hs-identifier hs-var">addr2Int#</span></a></span><span> </span><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679535052"><span class="hs-identifier hs-var">a#</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-95"></span><span>
</span><span id="line-96"></span><span class="hs-comment">-- | casts a @WordPtr@ to a @Ptr@</span><span>
</span><span id="line-97"></span><span id="local-6989586621679535757"><span class="annot"><a href="Foreign.Ptr.html#wordPtrToPtr"><span class="hs-identifier hs-type">wordPtrToPtr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Ptr.html#WordPtr"><span class="hs-identifier hs-type">WordPtr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679535757"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-98"></span><span id="wordPtrToPtr"><span class="annot"><span class="annottext">wordPtrToPtr :: forall a. WordPtr -&gt; Ptr a
</span><a href="Foreign.Ptr.html#wordPtrToPtr"><span class="hs-identifier hs-var hs-var">wordPtrToPtr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.Ptr.html#WordPtr"><span class="hs-identifier hs-type">WordPtr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#W%23"><span class="hs-identifier hs-type">W#</span></a></span><span> </span><span id="local-6989586621679535051"><span class="annot"><span class="annottext">Word#
</span><a href="#local-6989586621679535051"><span class="hs-identifier hs-var">w#</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Addr# -&gt; Ptr a
forall a. Addr# -&gt; Ptr a
</span><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-var">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int# -&gt; Addr#
</span><a href="../../ghc-prim/src/GHC.Prim.html#int2Addr%23"><span class="hs-identifier hs-var">int2Addr#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word# -&gt; Int#
</span><a href="../../ghc-prim/src/GHC.Prim.html#word2Int%23"><span class="hs-identifier hs-var">word2Int#</span></a></span><span> </span><span class="annot"><span class="annottext">Word#
</span><a href="#local-6989586621679535051"><span class="hs-identifier hs-var">w#</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-99"></span><span>
</span><span id="line-100"></span><span class="hs-comment">-- | casts a @Ptr@ to an @IntPtr@</span><span>
</span><span id="line-101"></span><span id="local-6989586621679535754"><span class="annot"><a href="Foreign.Ptr.html#ptrToIntPtr"><span class="hs-identifier hs-type">ptrToIntPtr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679535754"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.Ptr.html#IntPtr"><span class="hs-identifier hs-type">IntPtr</span></a></span></span><span>
</span><span id="line-102"></span><span id="ptrToIntPtr"><span class="annot"><span class="annottext">ptrToIntPtr :: forall a. Ptr a -&gt; IntPtr
</span><a href="Foreign.Ptr.html#ptrToIntPtr"><span class="hs-identifier hs-var hs-var">ptrToIntPtr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span id="local-6989586621679535050"><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679535050"><span class="hs-identifier hs-var">a#</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IntPtr
</span><a href="Foreign.Ptr.html#IntPtr"><span class="hs-identifier hs-var">IntPtr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int# -&gt; Int
</span><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-var">I#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Addr# -&gt; Int#
</span><a href="../../ghc-prim/src/GHC.Prim.html#addr2Int%23"><span class="hs-identifier hs-var">addr2Int#</span></a></span><span> </span><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679535050"><span class="hs-identifier hs-var">a#</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-103"></span><span>
</span><span id="line-104"></span><span class="hs-comment">-- | casts an @IntPtr@ to a @Ptr@</span><span>
</span><span id="line-105"></span><span id="local-6989586621679535752"><span class="annot"><a href="Foreign.Ptr.html#intPtrToPtr"><span class="hs-identifier hs-type">intPtrToPtr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Ptr.html#IntPtr"><span class="hs-identifier hs-type">IntPtr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679535752"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-106"></span><span id="intPtrToPtr"><span class="annot"><span class="annottext">intPtrToPtr :: forall a. IntPtr -&gt; Ptr a
</span><a href="Foreign.Ptr.html#intPtrToPtr"><span class="hs-identifier hs-var hs-var">intPtrToPtr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.Ptr.html#IntPtr"><span class="hs-identifier hs-type">IntPtr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679535049"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679535049"><span class="hs-identifier hs-var">i#</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Addr# -&gt; Ptr a
forall a. Addr# -&gt; Ptr a
</span><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-var">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int# -&gt; Addr#
</span><a href="../../ghc-prim/src/GHC.Prim.html#int2Addr%23"><span class="hs-identifier hs-var">int2Addr#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679535049"><span class="hs-identifier hs-var">i#</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-107"></span><span>
</span><span id="line-108"></span><span class="hs-comment">{-
Note [Exporting constructors of marshallable foreign types]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
One might expect that IntPtr, WordPtr, and the other newtypes in the
Foreign.C.Types and System.Posix.Types modules to be abstract, but this is not
the case in GHC (see #5229 and #11983). In fact, we deliberately export
the constructors for these datatypes in order to satisfy a requirement of the
Haskell 2010 Report (&#167; 8.4.2) that if a newtype is used in a foreign
declaration, then its constructor must be visible.

This requirement was motivated by the fact that using a type in a foreign
declaration necessarily exposes some information about the type to the user,
so being able to use abstract types in a foreign declaration breaks their
abstraction (see #3008). As a result, the constructors of all FFI-related
newtypes in base must be exported in order to be useful for FFI programming,
even at the cost of exposing their underlying, architecture-dependent types.
-}</span><span>
</span><span id="line-125"></span></pre></body></html>